package com.wanmait.movie.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.wanmait.movie.entity.Combo;
import com.wanmait.movie.entity.VO.ComboVO;
import com.wanmait.movie.service.ComboService;
import com.wanmait.movie.service.FoodToComboService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;
import java.util.List;

@RestController
@RequestMapping("manage/combo")
public class ManageComboController {
    @Resource
    private ComboService comboService;
    @Resource
    private FoodToComboService foodToComboService;

    @RequestMapping("list")
    public AjaxResult list(@Min(1) @RequestParam(required = false, defaultValue = "1")Integer pageNum,  @RequestParam(required = false, defaultValue = "5")Integer pageSize){
        return AjaxResult.success(comboService.getCombo(pageNum,pageSize));
    }
    @PostMapping("add")
    public AjaxResult add(@RequestBody ComboVO comboVO){
        return AjaxResult.success(comboService.saveOrUpdate(comboVO));
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        if(!comboService.removeById(id)){
            return  AjaxResult.error(505,"删除错误");
        }
        return AjaxResult.success(comboService.removeById(id));
    }

    @GetMapping("findFoodListByComboId")
    public AjaxResult findFoodListByComboId(Integer id){
        return AjaxResult.success(foodToComboService.findFoodListByComboId(id));
    }
}
